package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/7/22 11:44
 * @Version 1.0
 */
@Controller
public class CartController {


    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 添加成功的购物车页面。
     * window.location.href = 'http://cart.gmall.com/addCart.html?skuId=' + this.skuId + '&skuNum=' + this.skuNum
     * @return
     */
    @GetMapping("addCart.html")
    public String addCart(HttpServletRequest request){
        String skuId = request.getParameter("skuId");
        String skuNum = request.getParameter("skuNum");
        SkuInfo skuInfo = productFeignClient.getSkuInfo(Long.parseLong(skuId));
        //  存储数据
        request.setAttribute("skuInfo",skuInfo);
        request.setAttribute("skuNum",skuNum);
        //  添加成功页面。
        return "cart/addCart";
    }

    /**
     * 购物车列表
     * @return
     */
    @GetMapping("cart.html")
    public String cartIndex(){
        //  购物车列表页面。异步加载
        return "cart/index";
    }
}
